package com.yang.app.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.yang.app.entity.User;
import com.yang.app.service.IUserService;
import com.yang.app.service.impl.UserServiceImpl;

@Controller
@RequestMapping(value = "/yang")
public class UserController {
	/*private UserMapper userMapper = null;
	
	@Autowired
	public void setUserMapper(UserMapper userMapper) {
		this.userMapper = userMapper;
	}
	
	

	@RequestMapping(method = RequestMethod.GET)
	public String getAllUser(ModelMap model){
		List<User> users = userMapper.getAllUser();
		System.out.println(users);
		model.addAttribute("users", users);
		return "index";
	}
	
	@RequestMapping(value = "/add")
	public ModelAndView add(HttpServletRequest request,
			HttpServletResponse response){
		ModelAndView mv = new ModelAndView("index");
		String userName = request.getParameter("userName");
		String password = request.getParameter("password");
		User user = new User();
		user.setUserName(userName);
		user.setPassword(password);
		userMapper.addUser(user);
		List<User> users = userMapper.getAllUser();
		mv.addObject("users", users);
		return mv;
	}
	
	@RequestMapping(value = "/delete")
	public ModelAndView delete(HttpServletRequest request,
			HttpServletResponse response){
		ModelAndView mv = new ModelAndView("index");
		String id = request.getParameter("id");
		userMapper.delete(Integer.parseInt(id));
		List<User> users = userMapper.getAllUser();
		mv.addObject("users", users);
		return mv;
	}
	
	@RequestMapping(value = "/update")
	public ModelAndView update(HttpServletRequest request,
			HttpServletResponse response){
		ModelAndView mv = new ModelAndView("index");
		String userName = request.getParameter("userName");
		String password = request.getParameter("password");
		String id = request.getParameter("id");
		User user = new User();
		user.setUserName(userName);
		user.setPassword(password);
		user.setId(Integer.parseInt(id));
		userMapper.update(user);
		List<User> users = userMapper.getAllUser();
		mv.addObject("users", users);
		return mv;
	}
	
	@RequestMapping(value = "/updateInit")
	public ModelAndView updateInit(HttpServletRequest request,
			HttpServletResponse response){
		ModelAndView mv = new ModelAndView("updateInit");
		String id = request.getParameter("id");
		userMapper.getUserById(Integer.parseInt(id));
		User user = userMapper.getUserById(Integer.parseInt(id));
		mv.addObject("user", user);
		return mv;
	}
*/
}
